package permission

import (
	"gin_demo/utility"

	"github.com/gin-gonic/gin"
)

var SPermission = sPermission{}

type sPermission struct{}

//@Summary  后台用权限查看接口
//@Success 200 {string} string json{"code","message"}
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/permission/list  [get]
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@version 1.0
func (role *sPermission) List(ctx *gin.Context) {
	req := PageList{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		List(ctx, req)
	}
}

//@Summary  后台权限添加接口
//@Success 200 {string} string json{"code","message"}
//@Param data body permission.AddPermissionReq{} true "权限添加请求参数"
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Router  /backend/permission/add  [post]
//@version 1.0
func (role *sPermission) Create(ctx *gin.Context) {
	req := AddPermissionReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Create(ctx, req)
	}
}

//@Summary  后台权限删除接口
//@Success 200 {string} string json{"code","message"}
//@Param data body permission.SoftDeleteReq{} true "权限删除请求参数"
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Router  /backend/permission/del  [delete]
//@version 1.0
func (role *sPermission) Delete(ctx *gin.Context) {
	req := SoftDeleteReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Delete(ctx, req)
	}
}

//@Summary  后台权限更新接口
//@Success 200 {string} string json{"code","message"}
//@Param data body permission.UpdatePermissionReq{} true "权限更新请求参数"
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Router  /backend/permission/update  [put]
//@version 1.0
func (role *sPermission) Update(ctx *gin.Context) {
	req := UpdatePermissionReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Update(ctx, req)
	}
}
